package org.market.domain.strategy.service.rule.tree.impl;

import lombok.extern.slf4j.Slf4j;
import org.market.domain.strategy.model.valobj.RuleLogicCheckTypeVO;
import org.market.domain.strategy.service.rule.tree.IRuleTreeNode;
import org.market.domain.strategy.service.rule.tree.factory.DefaultRuleTreeFactory;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * @Author: Insight
 * @Description: TODO
 * @Date: 2025/2/25 下午10:05
 * @Version: 1.0
 */
@Slf4j
@Service
@Component("rule_lock")
public class RuleTreeLockNode implements IRuleTreeNode {

    public Long userRaffleCount = 10L;

    @Override
    public DefaultRuleTreeFactory.RuleActionEntity logic(String userId, Long StrategyId, Integer awardId,String ruleValue) {

        Long raffleCount = 0L;
        try {
            raffleCount = Long.valueOf(ruleValue);
        }catch (Exception e){
            log.error("次数锁异常"+ruleValue+"配置错误");
        }

        if (userRaffleCount >= raffleCount){
            log.info("用户抽奖次数满足");
            return DefaultRuleTreeFactory.RuleActionEntity.builder()
                    .ruleLogicCheckType(RuleLogicCheckTypeVO.ALLOW)
                    .build();
        }


        return DefaultRuleTreeFactory.RuleActionEntity.builder()
                .ruleLogicCheckType(RuleLogicCheckTypeVO.TAKE_OVER)
                .build();
    }
}
